package com.skypan.booklistmainactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class EditBookActivity extends AppCompatActivity {

    private EditText editTitle;
    private int position;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_book);
        editTitle = findViewById(R.id.edit_book_title);
        Intent intent = getIntent();
        position = intent.getIntExtra("position",0);
        String bookName = intent.getStringExtra("book_name");
        if (bookName != null){
            editTitle.setText(bookName);
        }

    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.edit_btn_ensure:
                Intent intent = new Intent(EditBookActivity.this, BookListMainActivity.class);
                intent.putExtra("book_name",editTitle.getText().toString());
                intent.putExtra("position",position);
                setResult(BookListFragment.RESULT_CODE_EDIT_DATA,intent);
                EditBookActivity.this.finish();
                break;
            case R.id.edit_btn_cancel:
                finish();
                break;
        }
    }
}